﻿Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports LibMain
Imports System.Data.Objects

<ServiceContract(Namespace:="")>
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)>
Public Class IsoService

    Private dbThing As TestEntities = New TestEntities
    <OperationContract()>
    Public Function GetImageFiles(ByVal fname As String) As List(Of FileRecord)
        Dim imgs = From t In dbThing.Images
                   Where t.FileName.Contains(fname)
                   Select New FileRecord() With {.id = t.id,
                                                .Datestamp = t.Datestamp,
                                                .Comment = t.Comment,
                                                .FileName = t.FileName,
                                                .ImageFile = t.ImageData}
        Return imgs.ToList
    End Function

    <OperationContract()>
    Public Function GetFilteredImageFiles(ByVal filename As String) As List(Of FileRecord)
        Dim imgs = From t In dbThing.RetrieveImages(filename)
                   Select New FileRecord() With {.id = t.id,
                                                .Datestamp = t.Datestamp,
                                                .Comment = t.Comment,
                                                .FileName = t.FileName,
                                                .ImageFile = t.ImageData}

        Return imgs.ToList
    End Function

    <OperationContract()>
    Public Sub DeleteImage(ByVal id As Integer)
        Dim img = (From t In dbThing.Images
                   Where t.id = id
                   Select t).SingleOrDefault
        dbThing.DeleteObject(img)
        dbThing.SaveChanges()
    End Sub

    <OperationContract()>
    Public Sub SaveDBchanges()
        dbThing.SaveChanges()
    End Sub

End Class
